package com.nsgf.library.data.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;

import androidx.annotation.NonNull;

import java.text.DecimalFormat;
import java.util.List;

public class ProductBean implements Parcelable {


    private String id;
    private String name;
    private String picUrl;
    private double marketPrice;
    private double retailPrice;
    private double price;
    private String spuId;
    private String createTime;
    private String updateTime;
    private String creator;
    private String updater;
    private String deleted;
    private String zhhtMerchantsType;
    private String freeShipping;
    private String tenantName;
    private List<ProductBean> list;
    private double categoryId;
    private String spuName;
    private double skuId;
    private double cartId;
    private double count;
    private List<PropertiesBean> properties;
    private String salesCount;
    private String property;

    protected ProductBean(Parcel in) {
        id = in.readString();
        name = in.readString();
        picUrl = in.readString();
        marketPrice = in.readDouble();
        retailPrice = in.readDouble();
        price = in.readDouble();
        spuId = in.readString();
        createTime = in.readString();
        updateTime = in.readString();
        creator = in.readString();
        updater = in.readString();
        deleted = in.readString();
        zhhtMerchantsType = in.readString();
        freeShipping = in.readString();
        tenantName = in.readString();
        list = in.createTypedArrayList(ProductBean.CREATOR);
        categoryId = in.readDouble();
        spuName = in.readString();
        skuId = in.readDouble();
        cartId = in.readDouble();
        count = in.readDouble();
        properties = in.createTypedArrayList(PropertiesBean.CREATOR);
        salesCount = in.readString();
        property = in.readString();
    }

    public static final Creator<ProductBean> CREATOR = new Creator<ProductBean>() {
        @Override
        public ProductBean createFromParcel(Parcel in) {
            return new ProductBean(in);
        }

        @Override
        public ProductBean[] newArray(int size) {
            return new ProductBean[size];
        }
    };

    public double getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(double categoryId) {
        this.categoryId = categoryId;
    }

    public String getSpuName() {
        return spuName;
    }

    public void setSpuName(String spuName) {
        this.spuName = spuName;
    }

    public double getSkuId() {
        return skuId;
    }

    public void setSkuId(double skuId) {
        this.skuId = skuId;
    }

    public double getCartId() {
        return cartId;
    }

    public void setCartId(double cartId) {
        this.cartId = cartId;
    }

    public double getCount() {
        return count;
    }

    public void setCount(double count) {
        this.count = count;
    }

    public List<PropertiesBean> getProperties() {
        return properties;
    }

    public void setProperties(List<PropertiesBean> properties) {
        this.properties = properties;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel parcel, int i) {
        parcel.writeString(id);
        parcel.writeString(name);
        parcel.writeString(picUrl);
        parcel.writeDouble(marketPrice);
        parcel.writeDouble(retailPrice);
        parcel.writeDouble(price);
        parcel.writeString(spuId);
        parcel.writeString(createTime);
        parcel.writeString(updateTime);
        parcel.writeString(creator);
        parcel.writeString(updater);
        parcel.writeString(deleted);
        parcel.writeString(zhhtMerchantsType);
        parcel.writeString(freeShipping);
        parcel.writeString(tenantName);
        parcel.writeTypedList(list);
        parcel.writeDouble(categoryId);
        parcel.writeString(spuName);
        parcel.writeDouble(skuId);
        parcel.writeDouble(cartId);
        parcel.writeDouble(count);
        parcel.writeTypedList(properties);
        parcel.writeString(salesCount);
        parcel.writeString(property);
    }

    public String getSalesCount() {
        return salesCount;
    }

    public String getSalesCountSrc() {
        return "销量：" + salesCount;
    }

    public void setSalesCount(String salesCount) {
        this.salesCount = salesCount;
    }

    public String getProperty() {
        return property;
    }

    public void setProperty(String property) {
        this.property = property;
    }

    public static class PropertiesBean implements Parcelable {
        /**
         * propertyId : 1
         * propertyName : 颜色
         * valueId : 41
         * valueName : 橙色
         */

        private double propertyId;
        private String propertyName;
        private double valueId;
        private String valueName;
        private boolean selected;

        protected PropertiesBean(Parcel in) {
            propertyId = in.readDouble();
            propertyName = in.readString();
            valueId = in.readDouble();
            valueName = in.readString();
            selected = in.readByte() != 0;
        }

        public static final Creator<PropertiesBean> CREATOR = new Creator<PropertiesBean>() {
            @Override
            public PropertiesBean createFromParcel(Parcel in) {
                return new PropertiesBean(in);
            }

            @Override
            public PropertiesBean[] newArray(int size) {
                return new PropertiesBean[size];
            }
        };

        public double getPropertyId() {
            return propertyId;
        }

        public void setPropertyId(double propertyId) {
            this.propertyId = propertyId;
        }

        public String getPropertyName() {
            return propertyName;
        }

        public void setPropertyName(String propertyName) {
            this.propertyName = propertyName;
        }

        public double getValueId() {
            return valueId;
        }

        public void setValueId(double valueId) {
            this.valueId = valueId;
        }

        public String getValueName() {
            return valueName;
        }

        public void setValueName(String valueName) {
            this.valueName = valueName;
        }

        public boolean isSelected() {
            return selected;
        }

        public void setSelected(boolean selected) {
            this.selected = selected;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(@NonNull Parcel parcel, int i) {
            parcel.writeDouble(propertyId);
            parcel.writeString(propertyName);
            parcel.writeDouble(valueId);
            parcel.writeString(valueName);
            parcel.writeByte((byte) (selected ? 1 : 0));
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPicUrl() {
        return picUrl;
    }

    public void setPicUrl(String picUrl) {
        this.picUrl = picUrl;
    }

    public String getMarketPrice() {
        DecimalFormat df = new DecimalFormat("#####0.00");
        return "原价:￥" + df.format(marketPrice / 100) + "元";
    }

    public void setMarketPrice(double marketPrice) {
        this.marketPrice = marketPrice;
    }

    public String getRetailPrice() {
        DecimalFormat df = new DecimalFormat("#####0.00");
        if (retailPrice > 0)
            return "￥" + df.format(retailPrice / 100);
        else
            return "￥" + df.format(price / 100);
    }


    public void setRetailPrice(double retailPrice) {
        this.retailPrice = retailPrice;
    }

    public String getSpuId() {
        return spuId;
    }

    public void setSpuId(String spuId) {
        this.spuId = spuId;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getUpdater() {
        return updater;
    }

    public void setUpdater(String updater) {
        this.updater = updater;
    }

    public String getDeleted() {
        return deleted;
    }

    public void setDeleted(String deleted) {
        this.deleted = deleted;
    }

    public String getZhhtMerchantsType() {
        return zhhtMerchantsType;
    }

    public String getZhhtMerchantsTypeSrc() {
        if ("3".equals(getZhhtMerchantsType()))
            return "";
        else if ("2".equals(getZhhtMerchantsType()))
            return "联盟店铺";
        return "";
    }

    public int getZhhtMerchantsTypeView() {
        if ("3".equals(getZhhtMerchantsType()))
            return View.GONE;
        else if ("2".equals(getZhhtMerchantsType()))
            return View.VISIBLE;
        return View.GONE;
    }

    public void setZhhtMerchantsType(String zhhtMerchantsType) {
        this.zhhtMerchantsType = zhhtMerchantsType;
    }

    public String getFreeShipping() {
        return freeShipping;
    }

    public void setFreeShipping(String freeShipping) {
        this.freeShipping = freeShipping;
    }

    public String getTenantName() {
        return tenantName;
    }

    public void setTenantName(String tenantName) {
        this.tenantName = tenantName;
    }

    public List<ProductBean> getList() {
        return list;
    }

    public void setList(List<ProductBean> list) {
        this.list = list;
    }

    public String getPrice() {

        DecimalFormat df = new DecimalFormat("#####0.00");
        return "￥" + df.format(price / 100);
    }

    public void setPrice(double price) {
        this.price = price;
    }
}
